package org.goochasca

import java.awt.Color

private[goochasca] object Colorific {
  private def appendColor(color: Color, sb: StringBuilder) {
    appendChannel(color.getRed, sb)
    appendChannel(color.getGreen, sb)
    appendChannel(color.getBlue, sb)
    if (color.getAlpha < 255)
      appendChannel(color.getAlpha, sb)
  }
  
  private def appendChannel(ch: Int, sb: StringBuilder) {
    if (ch < 16) sb append '0'
    sb append Integer.toHexString(ch)
  }

  def appendColors(colors: Collection[Color], sb: StringBuilder) {
    var first = true
    for (color <- colors) {
      if (first) {
        sb append "&chco=" 
        first = false
      } else {
        sb append ','
      }
      appendColor(color, sb)
    }

  }
}
